@file:Suppress("INVISIBLE_MEMBER","INVISIBLE_REFERENCE")

package com.gitee.wsl.resource.font

import androidx.compose.ui.text.font.Font
import com.gitee.wsl.platform.Platform
import com.gitee.wsl.platform.appContext
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.FontResource
import org.jetbrains.compose.resources.InternalResourceApi
import org.jetbrains.compose.resources.ResourceEnvironment
import org.jetbrains.compose.resources.getResourceItemByEnvironment


@OptIn(ExperimentalResourceApi::class, InternalResourceApi::class)
internal actual suspend fun loadFont(
    environment: ResourceEnvironment,
    font: FontSpec,
    resource: FontResource
) : Font {

    val path =  resource.getResourceItemByEnvironment(environment).path
    val context = Platform.appContext

    checkNotNull(context){
        "Compottie failed to initializer"
    }

    return Font(path, context.assets, font.weight, font.style)
}
